let proxyUrl='http://81.71.77.100:8080';//网关地址
function register() {
    let d={
        "email":$('#email').val(),
        "name":$('#name').val(),
        "pwd":$('#pwd').val(),
        "activeCode":""
    }
    $.ajax({
        type: "POST",
        url: proxyUrl+"/userAdmin/register",
        data: JSON.stringify(d),
        dataType: 'json',
        contentType:"application/json",
        success: function(result){
            alert(result);
        }
    });
}

function uploadBook() {
    let  url =  proxyUrl+"/bookAdmin/uploadBook"
    $( "#form_book" ).attr( 'action' ,url);
    $( "#form_book" ).attr( 'method' ,'post');
    $( "#form_book" ).submit();
}

function bookList() {
    $.ajax({
        type: "GET",
        url: proxyUrl+"/bookAdmin/book",
        dataType: 'json',
        contentType:"application/json",
        success: function(result){
            $('#t_b_info').empty();
            let imgUrlPre=proxyUrl+"/bookAdmin/book/img?bookImgName=";
            $('#t_b_info').append('<tr bgcolor="#5f9ea0">' +
                '                <th style="width: 100px">书名</th>' +
                '                <th style="width: 100px">作者</th>' +
                '                <th style="width: 100px">封面</th>' +
                '            </tr>');
            $.each(result,function(index,data){
                let imgUrl=imgUrlPre+data.bookImgName;
                $('#t_b_info').append('<tr>' +
                    '                <th style="width: 100px">'+data.bookName+'</th>' +
                    '                <th style="width: 100px">'+data.bookAuthor+'</th>' +
                    '                <th style="width: 100px;height: 100px"><img style="width: 80px;height: 80px" src="'+imgUrl+'"/></th>' +
                    '            </tr>');
            });
        }
    });
}


function userList() {
    $.ajax({
        type: "GET",
        url: proxyUrl+"/userAdmin/user",
        dataType: 'json',
        contentType:"application/json",
        success: function(result){
            $('#t_u_info').empty();
            $('#t_u_info').append('<tr bgcolor="#5f9ea0">' +
                '                <th style="width: 100px">姓名</th>' +
                '                <th style="width: 100px">邮箱</th>' +
                '                <th style="width: 100px">是否激活</th>' +
                '            </tr>');
            $.each(result,function(index,data){
                let active=data.active==0?'否':'是';
                $('#t_u_info').append('<tr>' +
                    '                <th style="width: 100px">'+data.name+'</th>' +
                    '                <th style="width: 100px">'+data.email+'</th>' +
                    '                <th style="width: 100px">'+active+'</th>' +
                    '            </tr>');
            });
        }
    });
}




$(function(){
    //第一种方式的简化方法
    getVersion();
});
function getVersion() {
    let getUserVersionUrl=proxyUrl+"/userAdmin/version";
    let getBookVersionUrl=proxyUrl+"/bookAdmin/version";
    $.ajax({
        type: "GET",
        url: getUserVersionUrl,
        success: function(result){
            $('#v_user').html(result);
        }
    });
    $.ajax({
        type: "GET",
        url: getBookVersionUrl,
        success: function(result){
            $('#v_book').html(result);
        }
    });
}